
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>应用01 原始服务器 · Python-Tutorial</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="网络01 原始服务器.html" />
    
    
    <link rel="prev" href="应用.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">Python基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="基础.html">
            
                <a href="基础.html">
            
                    
                    Python基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="01.html">
            
                <a href="01.html">
            
                    
                    基础01 Hello World!
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="01.html">
            
                <a href="01.html#python命令行">
            
                    
                    Python命令行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="01.html">
            
                <a href="01.html#写一段小程序">
            
                    
                    写一段小程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="01.html">
            
                <a href="01.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="02.html">
            
                <a href="02.html">
            
                    
                    基础02 基本数据类型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="02.html">
            
                <a href="02.html#变量不需要声明">
            
                    
                    变量不需要声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="02.html">
            
                <a href="02.html#回收变量名">
            
                    
                    回收变量名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.3" data-path="02.html">
            
                <a href="02.html#基本数据类型">
            
                    
                    基本数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.4" data-path="02.html">
            
                <a href="02.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="03.html">
            
                <a href="03.html">
            
                    
                    基础03 序列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="03.html">
            
                <a href="03.html#sequence-序列">
            
                    
                    sequence 序列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="03.html">
            
                <a href="03.html#元素的引用">
            
                    
                    元素的引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="03.html">
            
                <a href="03.html#其他引用方式">
            
                    
                    其他引用方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="03.html">
            
                <a href="03.html#字符串是元组">
            
                    
                    字符串是元组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.5" data-path="03.html">
            
                <a href="03.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="04.html">
            
                <a href="04.html">
            
                    
                    基础04 运算
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.4.1" data-path="04.html">
            
                <a href="04.html#数学运算">
            
                    
                    数学运算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.2" data-path="04.html">
            
                <a href="04.html#分支">
            
                    
                    分支
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.3" data-path="04.html">
            
                <a href="04.html#逻辑运算">
            
                    
                    逻辑运算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.4" data-path="04.html">
            
                <a href="04.html#pythonic-数据交换">
            
                    
                    Pythonic 数据交换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.5" data-path="04.html">
            
                <a href="04.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="05.html">
            
                <a href="05.html">
            
                    
                    基础05 缩进和选择
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.5.1" data-path="05.html">
            
                <a href="05.html#缩进">
            
                    
                    缩进
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5.2" data-path="05.html">
            
                <a href="05.html#if语句">
            
                    
                    if语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5.3" data-path="05.html">
            
                <a href="05.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="06.html">
            
                <a href="06.html">
            
                    
                    基础06 循环
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.6.1" data-path="06.html">
            
                <a href="06.html#for循环">
            
                    
                    for循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6.2" data-path="06.html">
            
                <a href="06.html#while循环">
            
                    
                    while循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6.3" data-path="06.html">
            
                <a href="06.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="07.html">
            
                <a href="07.html">
            
                    
                    基础07 函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.7.1" data-path="07.html">
            
                <a href="07.html#函数的定义">
            
                    
                    函数的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7.2" data-path="07.html">
            
                <a href="07.html#函数调用和参数传递">
            
                    
                    函数调用和参数传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7.3" data-path="07.html">
            
                <a href="07.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="08.html">
            
                <a href="08.html">
            
                    
                    基础08 面向对象的基本概念
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.8.1" data-path="08.html">
            
                <a href="08.html#相近对象，归为类">
            
                    
                    相近对象，归为类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.2" data-path="08.html">
            
                <a href="08.html#动作">
            
                    
                    动作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.3" data-path="08.html">
            
                <a href="08.html#子类">
            
                    
                    子类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4" data-path="08.html">
            
                <a href="08.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="09.html">
            
                <a href="09.html">
            
                    
                    基础09 面向对象的进一步拓展
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.9.1" data-path="09.html">
            
                <a href="09.html#调用类的其它信息">
            
                    
                    调用类的其它信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.2" data-path="09.html">
            
                <a href="09.html#init方法">
            
                    
                    __init__()方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.3" data-path="09.html">
            
                <a href="09.html#对象的性质">
            
                    
                    对象的性质
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="10.html">
            
                <a href="10.html">
            
                    
                    基础10 反过头来看看
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.10.1" data-path="10.html">
            
                <a href="10.html#list是一个类">
            
                    
                    list是一个类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.2" data-path="10.html">
            
                <a href="10.html#运算符是特殊方法">
            
                    
                    运算符是特殊方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.3" data-path="10.html">
            
                <a href="10.html#下一步">
            
                    
                    下一步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.4" data-path="10.html">
            
                <a href="10.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">Python进阶</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="进阶.html">
            
                <a href="进阶.html">
            
                    
                    进阶
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="intermediate01.html">
            
                <a href="intermediate01.html">
            
                    
                    进阶01 词典
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1.1" data-path="intermediate01.html">
            
                <a href="intermediate01.html#基本概念">
            
                    
                    基本概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.1.2" data-path="intermediate01.html">
            
                <a href="intermediate01.html#词典元素的循环调用">
            
                    
                    词典元素的循环调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.1.3" data-path="intermediate01.html">
            
                <a href="intermediate01.html#词典的常用方法">
            
                    
                    词典的常用方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.1.4" data-path="intermediate01.html">
            
                <a href="intermediate01.html#词典排序">
            
                    
                    词典排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.1.5" data-path="intermediate01.html">
            
                <a href="intermediate01.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="intermediate02.html">
            
                <a href="intermediate02.html">
            
                    
                    进阶02 文本文件的输入输出
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.2.1" data-path="intermediate02.html">
            
                <a href="intermediate02.html#创建文件对象">
            
                    
                    创建文件对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2.2" data-path="intermediate02.html">
            
                <a href="intermediate02.html#文件对象的方法">
            
                    
                    文件对象的方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2.3" data-path="intermediate02.html">
            
                <a href="intermediate02.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="intermediate03.html">
            
                <a href="intermediate03.html">
            
                    
                    进阶03 模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.3.1" data-path="intermediate03.html">
            
                <a href="intermediate03.html#引入模块">
            
                    
                    引入模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3.2" data-path="intermediate03.html">
            
                <a href="intermediate03.html#搜索路径">
            
                    
                    搜索路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3.3" data-path="intermediate03.html">
            
                <a href="intermediate03.html#模块包">
            
                    
                    模块包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3.4" data-path="intermediate03.html">
            
                <a href="intermediate03.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="intermediate04.html">
            
                <a href="intermediate04.html">
            
                    
                    进阶04 函数的参数对应
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.4.1" data-path="intermediate04.html">
            
                <a href="intermediate04.html#关键字传递">
            
                    
                    关键字传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4.2" data-path="intermediate04.html">
            
                <a href="intermediate04.html#参数默认值">
            
                    
                    参数默认值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4.3" data-path="intermediate04.html">
            
                <a href="intermediate04.html#包裹传递">
            
                    
                    包裹传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4.4" data-path="intermediate04.html">
            
                <a href="intermediate04.html#解包裹">
            
                    
                    解包裹
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4.5" data-path="intermediate04.html">
            
                <a href="intermediate04.html#混合">
            
                    
                    混合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4.6" data-path="intermediate04.html">
            
                <a href="intermediate04.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="intermediate05.html">
            
                <a href="intermediate05.html">
            
                    
                    进阶05 循环设计
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.5.1" data-path="intermediate05.html">
            
                <a href="intermediate05.html#range">
            
                    
                    range()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5.2" data-path="intermediate05.html">
            
                <a href="intermediate05.html#enumerate">
            
                    
                    enumerate()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5.3" data-path="intermediate05.html">
            
                <a href="intermediate05.html#zip">
            
                    
                    zip()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5.4" data-path="intermediate05.html">
            
                <a href="intermediate05.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="intermediate06.html">
            
                <a href="intermediate06.html">
            
                    
                    进阶06 循环对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.6.1" data-path="intermediate06.html">
            
                <a href="intermediate06.html#什么是循环对象">
            
                    
                    什么是循环对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6.2" data-path="intermediate06.html">
            
                <a href="intermediate06.html#迭代器">
            
                    
                    迭代器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6.3" data-path="intermediate06.html">
            
                <a href="intermediate06.html#生成器">
            
                    
                    生成器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6.4" data-path="intermediate06.html">
            
                <a href="intermediate06.html#表推导">
            
                    
                    表推导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6.5" data-path="intermediate06.html">
            
                <a href="intermediate06.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="intermediate07.html">
            
                <a href="intermediate07.html#">
            
                    
                    进阶07 函数对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.7.1" data-path="intermediate07.html">
            
                <a href="intermediate07.html#lambda函数">
            
                    
                    lambda函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7.2" data-path="intermediate07.html">
            
                <a href="intermediate07.html#函数作为参数传递">
            
                    
                    函数作为参数传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7.3" data-path="intermediate07.html">
            
                <a href="intermediate07.html#map函数">
            
                    
                    map()函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7.4" data-path="intermediate07.html">
            
                <a href="intermediate07.html#filter函数">
            
                    
                    filter()函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7.5" data-path="intermediate07.html">
            
                <a href="intermediate07.html#reduce函数">
            
                    
                    reduce()函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7.6" data-path="intermediate07.html">
            
                <a href="intermediate07.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="intermediate08.html">
            
                <a href="intermediate08.html#">
            
                    
                    进阶08 异常处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.8.1" data-path="intermediate08.html">
            
                <a href="intermediate08.html#异常处理">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8.2" data-path="intermediate08.html">
            
                <a href="intermediate08.html#抛出异常">
            
                    
                    抛出异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8.3" data-path="intermediate08.html">
            
                <a href="intermediate08.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="intermediate09.html">
            
                <a href="intermediate09.html#">
            
                    
                    进阶09 动态类型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.9.1" data-path="intermediate09.html">
            
                <a href="intermediate09.html#动态类型">
            
                    
                    动态类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9.2" data-path="intermediate09.html">
            
                <a href="intermediate09.html#从动态类型看函数的参数传递">
            
                    
                    从动态类型看函数的参数传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9.3" data-path="intermediate09.html">
            
                <a href="intermediate09.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="快速教程总结.html">
            
                <a href="快速教程总结.html">
            
                    
                    快速教程总结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="小题目 针对快速教程.html">
            
                <a href="小题目 针对快速教程.html">
            
                    
                    小题目 针对快速教程
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Python深入</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="深入.html">
            
                <a href="深入.html">
            
                    
                    Python深入
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="深入01 特殊方法与多范式.html">
            
                <a href="深入01 特殊方法与多范式.html#python深入01-特殊方法与多范式">
            
                    
                    深入01 特殊方法与多范式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1.1" data-path="深入01 特殊方法与多范式.html">
            
                <a href="深入01 特殊方法与多范式.html#运算符">
            
                    
                    运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.1.2" data-path="深入01 特殊方法与多范式.html">
            
                <a href="深入01 特殊方法与多范式.html#内置函数">
            
                    
                    内置函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.1.3" data-path="深入01 特殊方法与多范式.html">
            
                <a href="深入01 特殊方法与多范式.html#表list元素引用">
            
                    
                    表(list)元素引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.1.4" data-path="深入01 特殊方法与多范式.html">
            
                <a href="深入01 特殊方法与多范式.html#函数">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.1.5" data-path="深入01 特殊方法与多范式.html">
            
                <a href="深入01 特殊方法与多范式.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="深入02 上下文管理器.html">
            
                <a href="深入02 上下文管理器.html">
            
                    
                    深入02 上下文管理器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.2.1" data-path="深入02 上下文管理器.html">
            
                <a href="深入02 上下文管理器.html#关闭文件">
            
                    
                    关闭文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2.2" data-path="深入02 上下文管理器.html">
            
                <a href="深入02 上下文管理器.html#自定义">
            
                    
                    自定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2.3" data-path="深入02 上下文管理器.html">
            
                <a href="深入02 上下文管理器.html#总结：">
            
                    
                    总结：
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="深入03 对象的属性.html">
            
                <a href="深入03 对象的属性.html">
            
                    
                    深入03 对象的属性
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.3.1" data-path="深入03 对象的属性.html">
            
                <a href="深入03 对象的属性.html#属性的dict系统">
            
                    
                    属性的__dict__系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3.2" data-path="深入03 对象的属性.html">
            
                <a href="深入03 对象的属性.html#特性">
            
                    
                    特性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3.3" data-path="深入03 对象的属性.html">
            
                <a href="深入03 对象的属性.html#使用特殊方法getattr">
            
                    
                    使用特殊方法__getattr__
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3.4" data-path="深入03 对象的属性.html">
            
                <a href="深入03 对象的属性.html#即时生成属性的其他方式">
            
                    
                    即时生成属性的其他方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3.5" data-path="深入03 对象的属性.html">
            
                <a href="深入03 对象的属性.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="深入04 闭包.html">
            
                <a href="深入04 闭包.html">
            
                    
                    深入04 闭包
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.4.1" data-path="深入04 闭包.html">
            
                <a href="深入04 闭包.html#函数对象的作用域">
            
                    
                    函数对象的作用域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4.2" data-path="深入04 闭包.html">
            
                <a href="深入04 闭包.html#闭包">
            
                    
                    闭包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4.3" data-path="深入04 闭包.html">
            
                <a href="深入04 闭包.html#闭包与并行运算">
            
                    
                    闭包与并行运算
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="深入05 装饰器.html">
            
                <a href="深入05 装饰器.html">
            
                    
                    深入05 装饰器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.5.1" data-path="深入05 装饰器.html">
            
                <a href="深入05 装饰器.html#装饰函数和方法">
            
                    
                    装饰函数和方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5.2" data-path="深入05 装饰器.html">
            
                <a href="深入05 装饰器.html#含参的装饰器">
            
                    
                    含参的装饰器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5.3" data-path="深入05 装饰器.html">
            
                <a href="深入05 装饰器.html#装饰类">
            
                    
                    装饰类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5.4" data-path="深入05 装饰器.html">
            
                <a href="深入05 装饰器.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.1.6" data-path="深入06 内存管理.html">
            
                <a href="深入06 内存管理.html">
            
                    
                    深入06 内存管理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.6.1" data-path="深入06 内存管理.html">
            
                <a href="深入06 内存管理.html#对象的内存使用">
            
                    
                    对象的内存使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6.2" data-path="深入06 内存管理.html">
            
                <a href="深入06 内存管理.html#对象引用对象">
            
                    
                    对象引用对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6.3" data-path="深入06 内存管理.html">
            
                <a href="深入06 内存管理.html#引用减少">
            
                    
                    引用减少
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6.4" data-path="深入06 内存管理.html">
            
                <a href="深入06 内存管理.html#垃圾回收">
            
                    
                    垃圾回收
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6.5" data-path="深入06 内存管理.html">
            
                <a href="深入06 内存管理.html#分代回收">
            
                    
                    分代回收
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6.6" data-path="深入06 内存管理.html">
            
                <a href="深入06 内存管理.html#孤立的引用环">
            
                    
                    孤立的引用环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6.7" data-path="深入06 内存管理.html">
            
                <a href="深入06 内存管理.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">Python补充</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="补充.html">
            
                <a href="补充.html">
            
                    
                    Python补充
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="补充01 序列的方法.html">
            
                <a href="补充01 序列的方法.html">
            
                    
                    补充01 序列的方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html">
            
                    
                    补充02 小技巧
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.2.1" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html#import模块">
            
                    
                    import模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2.2" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html#查询">
            
                    
                    查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2.3" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html#使用中文以及其它非ascii编码">
            
                    
                    使用中文(以及其它非ASCII编码)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2.4" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html#表示2进制，8进制和16进制数字">
            
                    
                    表示2进制，8进制和16进制数字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2.5" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html#注释">
            
                    
                    注释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2.6" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html#搜索路径">
            
                    
                    搜索路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2.7" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html#脚本与命令行结合">
            
                    
                    脚本与命令行结合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2.8" data-path="补充02 小技巧.html">
            
                <a href="补充02 小技巧.html#安装非标准包">
            
                    
                    安装非标准包
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="补充03 内置函数清单.html">
            
                <a href="补充03 内置函数清单.html">
            
                    
                    补充03 内置函数清单
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.3.1" data-path="补充03 内置函数清单.html">
            
                <a href="补充03 内置函数清单.html#数学运算">
            
                    
                    数学运算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3.2" data-path="补充03 内置函数清单.html">
            
                <a href="补充03 内置函数清单.html#类型转换">
            
                    
                    类型转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3.3" data-path="补充03 内置函数清单.html">
            
                <a href="补充03 内置函数清单.html#类，对象，属性">
            
                    
                    序列操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3.4" data-path="补充03 内置函数清单.html">
            
                <a href="补充03 内置函数清单.html#编译，执行">
            
                    
                    编译，执行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3.5" data-path="补充03 内置函数清单.html">
            
                <a href="补充03 内置函数清单.html#其他">
            
                    
                    其他
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="补充04 简史.html">
            
                <a href="补充04 简史.html">
            
                    
                    补充04 简史
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.4.1" data-path="补充04 简史.html">
            
                <a href="补充04 简史.html#python的起源">
            
                    
                    Python的起源
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4.2" data-path="补充04 简史.html">
            
                <a href="补充04 简史.html#python的诞生">
            
                    
                    Python的诞生
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4.3" data-path="补充04 简史.html">
            
                <a href="补充04 简史.html#python启示录">
            
                    
                    Python启示录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="补充05 字符串格式化.html">
            
                <a href="补充05 字符串格式化.html">
            
                    
                    补充05 字符串格式化 (%操作符)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.5.1" data-path="补充05 字符串格式化.html">
            
                <a href="补充05 字符串格式化.html#模板">
            
                    
                    模板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5.2" data-path="补充05 字符串格式化.html">
            
                <a href="补充05 字符串格式化.html#格式符">
            
                    
                    格式符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5.3" data-path="补充05 字符串格式化.html">
            
                <a href="补充05 字符串格式化.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="补充06 python之道.html">
            
                <a href="补充06 python之道.html">
            
                    
                    补充06 Python之道
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.6.1" data-path="补充06 python之道.html">
            
                <a href="补充06 python之道.html#历史">
            
                    
                    历史
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">Python标准库</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="标准库.html">
            
                <a href="标准库.html">
            
                    
                    Python标准库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="标准库——走马观花.html">
            
                <a href="标准库——走马观花.html">
            
                    
                    标准库——走马观花
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1.1" data-path="标准库——走马观花.html">
            
                <a href="标准库——走马观花.html#第一类：python增强">
            
                    
                    第一类：Python增强
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.1.2" data-path="标准库——走马观花.html">
            
                <a href="标准库——走马观花.html#第二类：系统互动">
            
                    
                    第二类：系统互动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.1.3" data-path="标准库——走马观花.html">
            
                <a href="标准库——走马观花.html#第三类：网络">
            
                    
                    第三类：网络
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="标准库的学习准备.html">
            
                <a href="标准库的学习准备.html">
            
                    
                    标准库的学习准备
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.2.1" data-path="标准库的学习准备.html">
            
                <a href="标准库的学习准备.html#硬件原理">
            
                    
                    硬件原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2.2" data-path="标准库的学习准备.html">
            
                <a href="标准库的学习准备.html#操作系统">
            
                    
                    操作系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2.3" data-path="标准库的学习准备.html">
            
                <a href="标准库的学习准备.html#网络">
            
                    
                    网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2.4" data-path="标准库的学习准备.html">
            
                <a href="标准库的学习准备.html#算法与数据结构">
            
                    
                    算法与数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2.5" data-path="标准库的学习准备.html">
            
                <a href="标准库的学习准备.html#数据库">
            
                    
                    数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2.6" data-path="标准库的学习准备.html">
            
                <a href="标准库的学习准备.html#加密和文本编码">
            
                    
                    加密和文本编码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2.7" data-path="标准库的学习准备.html">
            
                <a href="标准库的学习准备.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.3" data-path="STL01.html">
            
                <a href="STL01.html">
            
                    
                    标准库01 正则表达式 (re包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.3.1" data-path="STL01.html">
            
                <a href="STL01.html#语法">
            
                    
                    语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.3.2" data-path="STL01.html">
            
                <a href="STL01.html#正则表达式的函数">
            
                    
                    正则表达式的函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.3.3" data-path="STL01.html">
            
                <a href="STL01.html#写一个正则表达式">
            
                    
                    写一个正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.3.4" data-path="STL01.html">
            
                <a href="STL01.html#对比research和rematch">
            
                    
                    对比re.search和re.match
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.3.5" data-path="STL01.html">
            
                <a href="STL01.html#练习">
            
                    
                    练习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.3.6" data-path="STL01.html">
            
                <a href="STL01.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.4" data-path="STL02.html">
            
                <a href="STL02.html">
            
                    
                    标准库02 时间与日期 (time, datetime包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.4.1" data-path="STL02.html">
            
                <a href="STL02.html#time包">
            
                    
                    time包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.4.2" data-path="STL02.html">
            
                <a href="STL02.html#datetime包">
            
                    
                    datetime包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.4.3" data-path="STL02.html">
            
                <a href="STL02.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.5" data-path="STL03.html">
            
                <a href="STL03.html">
            
                    
                    标准库03 路径与文件 (os.path包, glob包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.5.1" data-path="STL03.html">
            
                <a href="STL03.html#ospath包">
            
                    
                    os.path包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.5.2" data-path="STL03.html">
            
                <a href="STL03.html#glob包">
            
                    
                    glob包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.5.3" data-path="STL03.html">
            
                <a href="STL03.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.6" data-path="STL04.html">
            
                <a href="STL04.html">
            
                    
                    标准库04 文件管理 (部分os包，shutil包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.6.1" data-path="STL04.html">
            
                <a href="STL04.html#os包">
            
                    
                    os包
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.7" data-path="STL05.html">
            
                <a href="STL05.html">
            
                    
                    标准库05 存储对象 (pickle包，cPickle包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.7.1" data-path="STL05.html">
            
                <a href="STL05.html#pickle包">
            
                    
                    pickle包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.7.2" data-path="STL05.html">
            
                <a href="STL05.html#cpickle包">
            
                    
                    cPickle包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.7.3" data-path="STL05.html">
            
                <a href="STL05.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.8" data-path="STL06.html">
            
                <a href="STL06.html">
            
                    
                    标准库06 子进程 (subprocess包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.8.1" data-path="STL06.html">
            
                <a href="STL06.html#subprocess以及常用的封装函数">
            
                    
                    subprocess以及常用的封装函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.8.2" data-path="STL06.html">
            
                <a href="STL06.html#popen(">
            
                    
                    Popen()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.8.3" data-path="STL06.html">
            
                <a href="STL06.html#子进程的文本流控制">
            
                    
                    子进程的文本流控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.8.4" data-path="STL06.html">
            
                <a href="STL06.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.9" data-path="STL07.html">
            
                <a href="STL07.html">
            
                    
                    标准库07 信号 (signal包，部分os包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.9.1" data-path="STL07.html">
            
                <a href="STL07.html#定义信号名">
            
                    
                    定义信号名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.9.2" data-path="STL07.html">
            
                <a href="STL07.html#预设信号处理函数">
            
                    
                    预设信号处理函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.9.3" data-path="STL07.html">
            
                <a href="STL07.html#定时发出sigalrm信号">
            
                    
                    定时发出SIGALRM信号
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.9.4" data-path="STL07.html">
            
                <a href="STL07.html#发送信号">
            
                    
                    发送信号
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.9.5" data-path="STL07.html">
            
                <a href="STL07.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.10" data-path="STL08.html">
            
                <a href="STL08.html">
            
                    
                    标准库08 多线程与同步 (threading包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.10.1" data-path="STL08.html">
            
                <a href="STL08.html#多线程售票以及同步">
            
                    
                    多线程售票以及同步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.10.2" data-path="STL08.html">
            
                <a href="STL08.html#oop创建线程">
            
                    
                    OOP创建线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.10.3" data-path="STL08.html">
            
                <a href="STL08.html#其他">
            
                    
                    其他
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.10.4" data-path="STL08.html">
            
                <a href="STL08.html#练习">
            
                    
                    练习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.10.5" data-path="STL08.html">
            
                <a href="STL08.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.11" data-path="STL09.html">
            
                <a href="STL09.html">
            
                    
                    标准库09 当前进程信息 (部分os包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.11.1" data-path="STL09.html">
            
                <a href="STL09.html#进程信息">
            
                    
                    进程信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.11.2" data-path="STL09.html">
            
                <a href="STL09.html#saved-uid和saved-gid">
            
                    
                    saved UID和saved GID
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.11.3" data-path="STL09.html">
            
                <a href="STL09.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.12" data-path="STL10.html">
            
                <a href="STL10.html">
            
                    
                    标准库10 多进程初步 (multiprocessing包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.12.1" data-path="STL10.html">
            
                <a href="STL10.html#threading和multiprocessing">
            
                    
                    threading和multiprocessing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.12.2" data-path="STL10.html">
            
                <a href="STL10.html#Pipe和Queue">
            
                    
                    Pipe和Queue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.12.3" data-path="STL10.html">
            
                <a href="STL10.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.13" data-path="STL11.html">
            
                <a href="STL11.html">
            
                    
                    标准库11 多进程探索 (multiprocessing包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.13.1" data-path="STL11.html">
            
                <a href="STL11.html#进程池">
            
                    
                    进程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.13.2" data-path="STL11.html">
            
                <a href="STL11.html#练习">
            
                    
                    练习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.13.3" data-path="STL11.html">
            
                <a href="STL11.html#共享资源">
            
                    
                    共享资源
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.13.3.1" data-path="STL11.html">
            
                <a href="STL11.html#共享内存">
            
                    
                    共享内存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.13.3.2" data-path="STL11.html">
            
                <a href="STL11.html#manager">
            
                    
                    Manager
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.13.4" data-path="STL11.html">
            
                <a href="STL11.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.14" data-path="STL12.html">
            
                <a href="STL12.html">
            
                    
                    标准库12 数学与随机数 (math包，random包)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.14.1" data-path="STL12.html">
            
                <a href="STL12.html#math包">
            
                    
                    math包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.14.2" data-path="STL12.html">
            
                <a href="STL12.html#random包">
            
                    
                    random包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.14.3" data-path="STL12.html">
            
                <a href="STL12.html#练习">
            
                    
                    练习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.14.4" data-path="STL12.html">
            
                <a href="STL12.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.15" data-path="STL13 循环器 itertools.html">
            
                <a href="STL13 循环器 itertools.html">
            
                    
                    标准库13 循环器 (itertools)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.15.1" data-path="STL13 循环器 itertools.html">
            
                <a href="STL13 循环器 itertools.html#无穷循环器">
            
                    
                    无穷循环器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.15.2" data-path="STL13 循环器 itertools.html">
            
                <a href="STL13 循环器 itertools.html#函数式工具">
            
                    
                    函数式工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.15.3" data-path="STL13 循环器 itertools.html">
            
                <a href="STL13 循环器 itertools.html#组合工具">
            
                    
                    组合工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.15.4" data-path="STL13 循环器 itertools.html">
            
                <a href="STL13 循环器 itertools.html#groupby">
            
                    
                    groupby()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.15.5" data-path="STL13 循环器 itertools.html">
            
                <a href="STL13 循环器 itertools.html#其它工具">
            
                    
                    其它工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.15.6" data-path="STL13 循环器 itertools.html">
            
                <a href="STL13 循环器 itertools.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.16" data-path="STL14 数据库 sqlite3.html">
            
                <a href="STL14 数据库 sqlite3.html">
            
                    
                    标准库14 数据库 (sqlite3)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.16.1" data-path="STL14 数据库 sqlite3.html">
            
                <a href="STL14 数据库 sqlite3.html#创建数据库">
            
                    
                    创建数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.16.2" data-path="STL14 数据库 sqlite3.html">
            
                <a href="STL14 数据库 sqlite3.html#插入数据">
            
                    
                    插入数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.16.3" data-path="STL14 数据库 sqlite3.html">
            
                <a href="STL14 数据库 sqlite3.html#查询">
            
                    
                    查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.16.4" data-path="STL14 数据库 sqlite3.html">
            
                <a href="STL14 数据库 sqlite3.html#更新与删除">
            
                    
                    更新与删除
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.16.5" data-path="STL14 数据库 sqlite3.html">
            
                <a href="STL14 数据库 sqlite3.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">Python应用</li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="应用.html">
            
                <a href="应用.html">
            
                    
                    Python应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="6.1.1" data-path="网络01 原始服务器.html">
            
                <a href="网络01 原始服务器.html">
            
                    
                    应用01 原始服务器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1.1.1" data-path="网络01 原始服务器.html">
            
                <a href="网络01 原始服务器.html#tcpip和socket">
            
                    
                    TCP/IP和socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.1.2" data-path="网络01 原始服务器.html">
            
                <a href="网络01 原始服务器.html#tcp-socket">
            
                    
                    TCP socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.1.3" data-path="网络01 原始服务器.html">
            
                <a href="网络01 原始服务器.html#基于tcp-socket的http服务器">
            
                    
                    基于TCP socket的HTTP服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.1.4" data-path="网络01 原始服务器.html">
            
                <a href="网络01 原始服务器.html#深入http服务器程序">
            
                    
                    深入HTTP服务器程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.1.5" data-path="网络01 原始服务器.html">
            
                <a href="网络01 原始服务器.html#使用浏览器实验">
            
                    
                    使用浏览器实验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.1.6" data-path="网络01 原始服务器.html">
            
                <a href="网络01 原始服务器.html#探索的方向">
            
                    
                    探索的方向
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6.1.2" data-path="网络02 服务器进化.html">
            
                <a href="网络02 服务器进化.html">
            
                    
                    应用02 服务器进化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1.2.1" data-path="网络02 服务器进化.html">
            
                <a href="网络02 服务器进化.html#支持post">
            
                    
                    支持POST
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.2.2" data-path="网络02 服务器进化.html">
            
                <a href="网络02 服务器进化.html#使用socketserver">
            
                    
                    使用SocketServer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.2.3" data-path="网络02 服务器进化.html">
            
                <a href="网络02 服务器进化.html#simplehttpserver:-使用静态文件来回应请求">
            
                    
                    SimpleHTTPServer: 使用静态文件来回应请求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.2.4" data-path="网络02 服务器进化.html">
            
                <a href="网络02 服务器进化.html#cgihttpserver：使用静态文件或者cgi来回应请求">
            
                    
                    CGIHTTPServer：使用静态文件或者CGI来回应请求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.2.5" data-path="网络02 服务器进化.html">
            
                <a href="网络02 服务器进化.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6.1.3" data-path="网络03 使用pyqt制作视频播放器.html">
            
                <a href="网络03 使用pyqt制作视频播放器.html">
            
                    
                    应用03 使用PyQT制作视频播放器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1.3.1" data-path="网络03 使用pyqt制作视频播放器.html">
            
                <a href="网络03 使用pyqt制作视频播放器.html#视频播放器">
            
                    
                    视频播放器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.3.2" data-path="网络03 使用pyqt制作视频播放器.html">
            
                <a href="网络03 使用pyqt制作视频播放器.html#视图部分">
            
                    
                    视图部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.3.3" data-path="网络03 使用pyqt制作视频播放器.html">
            
                <a href="网络03 使用pyqt制作视频播放器.html#多线程">
            
                    
                    多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.3.4" data-path="网络03 使用pyqt制作视频播放器.html">
            
                <a href="网络03 使用pyqt制作视频播放器.html#信号与槽">
            
                    
                    信号与槽
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">被解放的姜戈</li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="被解放的姜戈.html">
            
                <a href="被解放的姜戈.html">
            
                    
                    被解放的姜戈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.1" data-path="被解放的姜戈01 初试天涯.html">
            
                <a href="被解放的姜戈01 初试天涯.html">
            
                    
                    被解放的姜戈01 初试天涯
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.1.1" data-path="被解放的姜戈01 初试天涯.html">
            
                <a href="被解放的姜戈01 初试天涯.html#安装django">
            
                    
                    安装Django
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.1.2" data-path="被解放的姜戈01 初试天涯.html">
            
                <a href="被解放的姜戈01 初试天涯.html#启动">
            
                    
                    启动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.1.3" data-path="被解放的姜戈01 初试天涯.html">
            
                <a href="被解放的姜戈01 初试天涯.html#第一个网页">
            
                    
                    第一个网页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.1.4" data-path="被解放的姜戈01 初试天涯.html">
            
                <a href="被解放的姜戈01 初试天涯.html#增加app">
            
                    
                    增加app
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.1.5" data-path="被解放的姜戈01 初试天涯.html">
            
                <a href="被解放的姜戈01 初试天涯.html#增加app页面">
            
                    
                    增加APP页面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.1.6" data-path="被解放的姜戈01 初试天涯.html">
            
                <a href="被解放的姜戈01 初试天涯.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.2" data-path="被解放的姜戈02 庄园疑云.html">
            
                <a href="被解放的姜戈02 庄园疑云.html">
            
                    
                    被解放的姜戈02 庄园疑云
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.2.1" data-path="被解放的姜戈02 庄园疑云.html">
            
                <a href="被解放的姜戈02 庄园疑云.html#连接数据库">
            
                    
                    连接数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.2.2" data-path="被解放的姜戈02 庄园疑云.html">
            
                <a href="被解放的姜戈02 庄园疑云.html#创立模型">
            
                    
                    创立模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.2.3" data-path="被解放的姜戈02 庄园疑云.html">
            
                <a href="被解放的姜戈02 庄园疑云.html#显示数据">
            
                    
                    显示数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.2.4" data-path="被解放的姜戈02 庄园疑云.html">
            
                <a href="被解放的姜戈02 庄园疑云.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.3" data-path="被解放的姜戈03 所谓伊人.html">
            
                <a href="被解放的姜戈03 所谓伊人.html">
            
                    
                    被解放的姜戈03 所谓伊人
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.3.1" data-path="被解放的姜戈03 所谓伊人.html">
            
                <a href="被解放的姜戈03 所谓伊人.html#模板初体验">
            
                    
                    模板初体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.3.2" data-path="被解放的姜戈03 所谓伊人.html">
            
                <a href="被解放的姜戈03 所谓伊人.html#流程">
            
                    
                    流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.3.3" data-path="被解放的姜戈03 所谓伊人.html">
            
                <a href="被解放的姜戈03 所谓伊人.html#循环与选择">
            
                    
                    循环与选择
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.3.4" data-path="被解放的姜戈03 所谓伊人.html">
            
                <a href="被解放的姜戈03 所谓伊人.html#模板继承">
            
                    
                    模板继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.3.5" data-path="被解放的姜戈03 所谓伊人.html">
            
                <a href="被解放的姜戈03 所谓伊人.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.4" data-path="被解放的姜戈04 各取所需.html">
            
                <a href="被解放的姜戈04 各取所需.html">
            
                    
                    被解放的姜戈04 各取所需
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.4.1" data-path="被解放的姜戈04 各取所需.html">
            
                <a href="被解放的姜戈04 各取所需.html#html表格">
            
                    
                    html表格
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.4.2" data-path="被解放的姜戈04 各取所需.html">
            
                <a href="被解放的姜戈04 各取所需.html#post方法">
            
                    
                    POST方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.4.3" data-path="被解放的姜戈04 各取所需.html">
            
                <a href="被解放的姜戈04 各取所需.html#存储数据">
            
                    
                    存储数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.4.4" data-path="被解放的姜戈04 各取所需.html">
            
                <a href="被解放的姜戈04 各取所需.html#表格对象">
            
                    
                    表格对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.4.5" data-path="被解放的姜戈04 各取所需.html">
            
                <a href="被解放的姜戈04 各取所需.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.5" data-path="被解放的姜戈05 黑面管家.html">
            
                <a href="被解放的姜戈05 黑面管家.html">
            
                    
                    被解放的姜戈05 黑面管家
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.5.1" data-path="被解放的姜戈05 黑面管家.html">
            
                <a href="被解放的姜戈05 黑面管家.html#默认界面">
            
                    
                    默认界面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.5.2" data-path="被解放的姜戈05 黑面管家.html">
            
                <a href="被解放的姜戈05 黑面管家.html#复杂模型">
            
                    
                    复杂模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.5.3" data-path="被解放的姜戈05 黑面管家.html">
            
                <a href="被解放的姜戈05 黑面管家.html#自定义页面">
            
                    
                    自定义页面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.5.4" data-path="被解放的姜戈05 黑面管家.html">
            
                <a href="被解放的姜戈05 黑面管家.html#inline显示">
            
                    
                    Inline显示
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.5.5" data-path="被解放的姜戈05 黑面管家.html">
            
                <a href="被解放的姜戈05 黑面管家.html#列表页的显示">
            
                    
                    列表页的显示
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.5.6" data-path="被解放的姜戈05 黑面管家.html">
            
                <a href="被解放的姜戈05 黑面管家.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.6" data-path="被解放的姜戈06 假作真时.html">
            
                <a href="被解放的姜戈06 假作真时.html">
            
                    
                    被解放的姜戈06 假作真时
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.6.1" data-path="被解放的姜戈06 假作真时.html">
            
                <a href="被解放的姜戈06 假作真时.html#创建用户">
            
                    
                    创建用户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.6.2" data-path="被解放的姜戈06 假作真时.html">
            
                <a href="被解放的姜戈06 假作真时.html#用户登录">
            
                    
                    用户登录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.6.3" data-path="被解放的姜戈06 假作真时.html">
            
                <a href="被解放的姜戈06 假作真时.html#登出">
            
                    
                    登出
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.6.4" data-path="被解放的姜戈06 假作真时.html">
            
                <a href="被解放的姜戈06 假作真时.html#viewspy中的用户">
            
                    
                    views.py中的用户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.6.5" data-path="被解放的姜戈06 假作真时.html">
            
                <a href="被解放的姜戈06 假作真时.html#模板中的用户">
            
                    
                    模板中的用户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.6.6" data-path="被解放的姜戈06 假作真时.html">
            
                <a href="被解放的姜戈06 假作真时.html#用户注册">
            
                    
                    用户注册
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.6.7" data-path="被解放的姜戈06 假作真时.html">
            
                <a href="被解放的姜戈06 假作真时.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.7" data-path="被解放的姜戈07 马不停蹄.html">
            
                <a href="被解放的姜戈07 马不停蹄.html">
            
                    
                    被解放的姜戈07 马不停蹄
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.7.1" data-path="被解放的姜戈07 马不停蹄.html">
            
                <a href="被解放的姜戈07 马不停蹄.html#安装">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.7.2" data-path="被解放的姜戈07 马不停蹄.html">
            
                <a href="被解放的姜戈07 马不停蹄.html#静态文件">
            
                    
                    静态文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.7.3" data-path="被解放的姜戈07 马不停蹄.html">
            
                <a href="被解放的姜戈07 马不停蹄.html#其它">
            
                    
                    其它
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.7.4" data-path="被解放的姜戈07 马不停蹄.html">
            
                <a href="被解放的姜戈07 马不停蹄.html#总结">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.8" data-path="被解放的姜戈08 远走高飞.html">
            
                <a href="被解放的姜戈08 远走高飞.html">
            
                    
                    被解放的姜戈08 远走高飞
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.8.1" data-path="被解放的姜戈08 远走高飞.html">
            
                <a href="被解放的姜戈08 远走高飞.html#阿里云准备">
            
                    
                    阿里云准备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.8.2" data-path="被解放的姜戈08 远走高飞.html">
            
                <a href="被解放的姜戈08 远走高飞.html#安装django">
            
                    
                    安装Django
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.8.3" data-path="被解放的姜戈08 远走高飞.html">
            
                <a href="被解放的姜戈08 远走高飞.html#安装数据库和http服务器">
            
                    
                    安装数据库和HTTP服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.8.4" data-path="被解放的姜戈08 远走高飞.html">
            
                <a href="被解放的姜戈08 远走高飞.html#运行django服务器">
            
                    
                    运行Django服务器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="尾声.html">
            
                <a href="尾声.html">
            
                    
                    快速教程 尾声
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >应用01 原始服务器</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="python&#x7F51;&#x7EDC;01-&#x539F;&#x59CB;python&#x670D;&#x52A1;&#x5668;">Python&#x7F51;&#x7EDC;01 &#x539F;&#x59CB;Python&#x670D;&#x52A1;&#x5668;</h1>
<p>&#x4E4B;&#x524D;&#x6211;&#x7684;Python&#x6559;&#x7A0B;&#x4E2D;&#x6709;&#x4EBA;&#x7559;&#x8A00;&#xFF0C;&#x8868;&#x793A;&#x53EA;&#x5B66;Python&#x6CA1;&#x6709;&#x7528;&#xFF0C;&#x5FC5;&#x987B;&#x5B66;&#x4F1A;&#x4E00;&#x4E2A;&#x6846;&#x67B6;(&#x6BD4;&#x5982;Django&#x548C;web.py)&#x624D;&#x80FD;&#x627E;&#x5230;&#x5DE5;&#x4F5C;&#x3002;&#x800C;&#x6211;&#x7684;&#x60F3;&#x6CD5;&#x662F;&#xFF0C;&#x638C;&#x63E1;&#x4E00;&#x4E2A;&#x7C7B;&#x4F3C;&#x4E8E;&#x6846;&#x67B6;&#x7684;&#x9AD8;&#x7EA7;&#x5DE5;&#x5177;&#x662F;&#x6709;&#x7528;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x57FA;&#x7840;&#x7684;&#x4E1C;&#x897F;&#x53EF;&#x4EE5;&#x8BA9;&#x4F60;&#x6C38;&#x8FDC;&#x4E0D;&#x88AB;&#x6DD8;&#x6C70;&#x3002;&#x4E0D;&#x8981;&#x88AB;&#x5DE5;&#x5177;&#x9650;&#x5236;&#x4E86;&#x81EA;&#x5DF1;&#x7684;&#x53D1;&#x5C55;&#x3002;&#x4ECA;&#x5929;&#xFF0C;&#x6211;&#x5728;&#x8FD9;&#x91CC;&#x60F3;&#x8981;&#x5C55;&#x793A;&#x7684;&#xFF0C;&#x5C31;&#x662F;&#x4E0D;&#x4F7F;&#x7528;&#x6846;&#x67B6;&#xFF0C;&#x751A;&#x81F3;&#x4E0D;&#x4F7F;&#x7528;Python&#x6807;&#x51C6;&#x5E93;&#x4E2D;&#x7684;&#x9AD8;&#x7EA7;&#x5305;&#xFF0C;&#x53EA;&#x4F7F;&#x7528;&#x6807;&#x51C6;&#x5E93;&#x4E2D;&#x7684;socket&#x63A5;&#x53E3;(&#x6211;&#x4E0D;&#x662F;&#x5F88;&#x660E;&#x767D;&#x5957;&#x63A5;&#x5B57;&#x8FD9;&#x4E2A;&#x7FFB;&#x8BD1;&#xFF0C;&#x6240;&#x4EE5;&#x4F7F;&#x7528;socket&#x7684;&#x82F1;&#x6587;&#x540D;&#x5B57;)&#xFF0C;&#x5199;&#x4E00;&#x4E2A;Python&#x670D;&#x52A1;&#x5668;&#x3002;</p>
<p>&#x5728;&#x5F53;&#x4ECA;Python&#x670D;&#x52A1;&#x5668;&#x6846;&#x67B6; (framework, &#x6BD4;&#x5982;Django, Twisted, web.py&#x7B49;&#x7B49;) &#x6A2A;&#x884C;&#x7684;&#x65F6;&#x4EE3;&#xFF0C;&#x4ECE;&#x5E95;&#x5C42;&#x7684;socket&#x5F00;&#x59CB;&#x5199;&#x670D;&#x52A1;&#x5668;&#x4F3C;&#x4E4E;&#x662F;&#x4E00;&#x4E2A;&#x51FA;&#x529B;&#x4E0D;&#x8BA8;&#x597D;&#x7684;&#x7B28;&#x65B9;&#x6CD5;&#x3002;&#x6846;&#x67B6;&#x7684;&#x610F;&#x4E49;&#x5728;&#x4E8E;&#x63A9;&#x76D6;&#x5E95;&#x5C42;&#x7684;&#x7EC6;&#x8282;&#xFF0C;&#x63D0;&#x4F9B;&#x4E00;&#x5957;&#x5BF9;&#x4E8E;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x66F4;&#x52A0;&#x53CB;&#x597D;&#x7684;API&#xFF0C;&#x5E76;&#x5904;&#x7406;&#x8BF8;&#x5982;MVC&#x7684;&#x5E03;&#x5C40;&#x95EE;&#x9898;&#x3002;&#x6846;&#x67B6;&#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x5FEB;&#x901F;&#x7684;&#x6784;&#x5EFA;&#x4E00;&#x4E2A;&#x6210;&#x578B;&#x800C;&#x4E14;&#x6210;&#x719F;&#x7684;Python&#x670D;&#x52A1;&#x5668;&#x3002;&#x7136;&#x800C;&#xFF0C;&#x6846;&#x67B6;&#x672C;&#x8EAB;&#x4E5F;&#x662F;&#x4F9D;&#x8D56;&#x4E8E;&#x5E95;&#x5C42;(&#x6BD4;&#x5982;socket)&#x3002;&#x5BF9;&#x4E8E;&#x5E95;&#x5C42;socket&#x7684;&#x4E86;&#x89E3;&#xFF0C;&#x4E0D;&#x4EC5;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x66F4;&#x597D;&#x7684;&#x4F7F;&#x7528;&#x6846;&#x67B6;&#xFF0C;&#x66F4;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x660E;&#x767D;&#x6846;&#x67B6;&#x662F;&#x5982;&#x4F55;&#x8BBE;&#x8BA1;&#x7684;&#x3002;&#x66F4;&#x8FDB;&#x4E00;&#x6B65;&#xFF0C;&#x5982;&#x679C;&#x62E5;&#x6709;&#x826F;&#x597D;&#x7684;&#x5E95;&#x5C42;socket&#x7F16;&#x7A0B;&#x77E5;&#x8BC6;&#x548C;&#x5176;&#x4ED6;&#x7CFB;&#x7EDF;&#x7F16;&#x7A0B;&#x77E5;&#x8BC6;&#xFF0C;&#x4F60;&#x5B8C;&#x5168;&#x53EF;&#x4EE5;&#x8BBE;&#x8BA1;&#x5E76;&#x5F00;&#x53D1;&#x4E00;&#x6B3E;&#x81EA;&#x5DF1;&#x7684;&#x6846;&#x67B6;&#x3002;&#x5982;&#x679C;&#x4F60;&#x53EF;&#x4EE5;&#x4ECE;&#x5E95;&#x5C42;socket&#x5F00;&#x59CB;&#xFF0C;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684;Python&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x652F;&#x6301;&#x7528;&#x6237;&#x5C42;&#x7684;&#x534F;&#x8BAE;&#xFF0C;&#x5E76;&#x5904;&#x7406;&#x597D;&#x8BF8;&#x5982;MVC(Model-View-Control)&#x3001;&#x591A;&#x7EBF;&#x7A0B;(threading)&#x7B49;&#x95EE;&#x9898;&#xFF0C;&#x5E76;&#x6574;&#x7406;&#x51FA;&#x4E00;&#x5957;&#x6E05;&#x6670;&#x7684;&#x51FD;&#x6570;&#x6216;&#x8005;&#x7C7B;&#xFF0C;&#x4F5C;&#x4E3A;&#x63A5;&#x53E3;(API)&#x5448;&#x73B0;&#x7ED9;&#x7528;&#x6237;&#xFF0C;&#x4F60;&#x5C31;&#x76F8;&#x5F53;&#x4E8E;&#x8BBE;&#x8BA1;&#x4E86;&#x4E00;&#x4E2A;&#x6846;&#x67B6;&#x3002;</p>
<p>socket&#x63A5;&#x53E3;&#x662F;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x63D0;&#x4F9B;&#x7684;&#x7CFB;&#x7EDF;&#x8C03;&#x7528;&#x3002;socket&#x7684;&#x4F7F;&#x7528;&#x5E76;&#x4E0D;&#x5C40;&#x9650;&#x4E8E;Python&#x8BED;&#x8A00;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x7528;C&#x6216;&#x8005;JAVA&#x6765;&#x5199;&#x51FA;&#x540C;&#x6837;&#x7684;socket&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x800C;&#x6240;&#x6709;&#x8BED;&#x8A00;&#x4F7F;&#x7528;socket&#x7684;&#x65B9;&#x5F0F;&#x90FD;&#x7C7B;&#x4F3C;(Apache&#x5C31;&#x662F;&#x4F7F;&#x7528;C&#x5B9E;&#x73B0;&#x7684;&#x670D;&#x52A1;&#x5668;)&#x3002;&#x800C;&#x4F60;&#x4E0D;&#x80FD;&#x8DE8;&#x8BED;&#x8A00;&#x7684;&#x4F7F;&#x7528;&#x6846;&#x67B6;&#x3002;&#x6846;&#x67B6;&#x7684;&#x597D;&#x5904;&#x5728;&#x4E8E;&#x5E2E;&#x4F60;&#x5904;&#x7406;&#x4E86;&#x4E00;&#x4E9B;&#x7EC6;&#x8282;&#xFF0C;&#x4ECE;&#x800C;&#x5B9E;&#x73B0;&#x5FEB;&#x901F;&#x5F00;&#x53D1;&#xFF0C;&#x4F46;&#x540C;&#x65F6;&#x53D7;&#x5230;Python&#x672C;&#x8EAB;&#x6027;&#x80FD;&#x7684;&#x9650;&#x5236;&#x3002;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x770B;&#x5230;&#xFF0C;&#x8BB8;&#x591A;&#x6210;&#x529F;&#x7684;&#x7F51;&#x7AD9;&#x90FD;&#x662F;&#x5229;&#x7528;&#x52A8;&#x6001;&#x8BED;&#x8A00;(&#x6BD4;&#x5982;Python, Ruby&#x6216;&#x8005;PHP&#xFF0C;&#x6BD4;&#x5982;twitter&#x548C;facebook)&#x5FEB;&#x901F;&#x5F00;&#x53D1;&#xFF0C;&#x5728;&#x7F51;&#x7AD9;&#x6210;&#x529F;&#x4E4B;&#x540E;&#xFF0C;&#x5C06;&#x4EE3;&#x7801;&#x8F6C;&#x6362;&#x6210;&#x8BF8;&#x5982;C&#x548C;JAVA&#x8FD9;&#x6837;&#x4E00;&#x4E9B;&#x6548;&#x7387;&#x6BD4;&#x8F83;&#x9AD8;&#x7684;&#x8BED;&#x8A00;&#xFF0C;&#x4ECE;&#x800C;&#x8BA9;&#x670D;&#x52A1;&#x5668;&#x80FD;&#x66F4;&#x6709;&#x6548;&#x7387;&#x7684;&#x9762;&#x5BF9;&#x6BCF;&#x5929;&#x4EBF;&#x4E07;&#x6B21;&#x7684;&#x8BF7;&#x6C42;&#x3002;&#x5728;&#x8FD9;&#x6837;&#x4E00;&#x4E9B;&#x65F6;&#x95F4;&#xFF0C;&#x5E95;&#x5C42;&#x7684;&#x91CD;&#x8981;&#x6027;&#xFF0C;&#x5C31;&#x8FDC;&#x8FDC;&#x8D85;&#x8FC7;&#x4E86;&#x6846;&#x67B6;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7684;&#x4E00;&#x7BC7;&#x6587;&#x7AE0;&#x867D;&#x7136;&#x662F;&#x5728;&#x8C08;JAVA&#xFF0C;&#x4F46;&#x6211;&#x89C9;&#x5F97;&#x4E5F;&#x9002;&#x7528;&#x4E8E;Python&#x7684;&#x6846;&#x67B6;&#x4E4B;&#x4E89;&#x3002;
<a href="http://yakovfain.com/2012/10/11/the-degradation-of-java-developers/" target="_blank">http://yakovfain.com/2012/10/11/the-degradation-of-java-developers/</a></p>
<h2 id="tcpip&#x548C;socket">TCP/IP&#x548C;socket</h2>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5BF9;&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#xFF0C;&#x7279;&#x522B;&#x662F;TCP/IP&#x534F;&#x8BAE;&#x548C;socket&#x6709;&#x4E00;&#x5B9A;&#x7684;&#x4E86;&#x89E3;&#x3002;socket&#x662F;&#x8FDB;&#x7A0B;&#x95F4;&#x901A;&#x4FE1;&#x7684;&#x4E00;&#x79CD;&#x65B9;&#x6CD5; (&#x53C2;&#x8003;Linux&#x8FDB;&#x7A0B;&#x95F4;&#x901A;&#x4FE1;)&#xFF0C;&#x5B83;&#x662F;&#x57FA;&#x4E8E;&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x534F;&#x8BAE;&#x7684;&#x4E0A;&#x5C42;&#x63A5;&#x53E3;&#x3002;socket&#x6709;&#x8BB8;&#x591A;&#x79CD;&#x7C7B;&#x578B;&#xFF0C;&#x6BD4;&#x5982;&#x57FA;&#x4E8E;TCP&#x534F;&#x8BAE;&#x6216;&#x8005;UDP&#x534F;&#x8BAE;(&#x4E24;&#x79CD;&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x534F;&#x8BAE;)&#x3002;&#x5176;&#x4E2D;&#x53C8;&#x4EE5;TCP socket&#x6700;&#x4E3A;&#x5E38;&#x7528;&#x3002;TCP socket&#x4E0E;&#x53CC;&#x5411;&#x7BA1;&#x9053;(duplex PIPE)&#x6709;&#x4E9B;&#x7C7B;&#x4F3C;&#xFF0C;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#x5411;socket&#x7684;&#x4E00;&#x7AEF;&#x5199;&#x5165;&#x6216;&#x8BFB;&#x53D6;&#x6587;&#x672C;&#x6D41;&#xFF0C;&#x800C;&#x53E6;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#x53EF;&#x4EE5;&#x4ECE;socket&#x7684;&#x53E6;&#x4E00;&#x7AEF;&#x8BFB;&#x53D6;&#x6216;&#x5199;&#x5165;&#xFF0C;&#x6BD4;&#x8F83;&#x7279;&#x522B;&#x662F;&#xFF0C;&#x8FD9;&#x4E24;&#x4E2A;&#x5EFA;&#x7ACB;socket&#x901A;&#x4FE1;&#x7684;&#x8FDB;&#x7A0B;&#x53EF;&#x4EE5;&#x5206;&#x522B;&#x5C5E;&#x4E8E;&#x4E24;&#x53F0;&#x4E0D;&#x540C;&#x7684;&#x8BA1;&#x7B97;&#x673A;&#x3002;&#x6240;&#x8C13;&#x7684;TCP&#x534F;&#x8BAE;&#xFF0C;&#x5C31;&#x662F;&#x89C4;&#x5B9A;&#x4E86;&#x4E00;&#x4E9B;&#x901A;&#x4FE1;&#x7684;&#x5B88;&#x5219;&#xFF0C;&#x4EE5;&#x4FBF;&#x5728;&#x7F51;&#x7EDC;&#x73AF;&#x5883;&#x4E0B;&#x80FD;&#x591F;&#x6709;&#x6548;&#x5B9E;&#x73B0;&#x4E0A;&#x8FF0;&#x8FDB;&#x7A0B;&#x95F4;&#x901A;&#x4FE1;&#x8FC7;&#x7A0B;&#x3002;&#x53CC;&#x5411;&#x7BA1;&#x9053;(duplex PIPE)&#x5B58;&#x6D3B;&#x4E8E;&#x540C;&#x4E00;&#x53F0;&#x7535;&#x8111;&#x4E2D;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x5FC5;&#x533A;&#x5206;&#x4E24;&#x4E2A;&#x8FDB;&#x7A0B;&#x7684;&#x6240;&#x5728;&#x8BA1;&#x7B97;&#x673A;&#x7684;&#x5730;&#x5740;&#xFF0C;&#x800C;socket&#x5FC5;&#x987B;&#x5305;&#x542B;&#x6709;&#x5730;&#x5740;&#x4FE1;&#x606F;&#xFF0C;&#x4EE5;&#x4FBF;&#x5B9E;&#x73B0;&#x7F51;&#x7EDC;&#x901A;&#x4FE1;&#x3002;&#x4E00;&#x4E2A;socket&#x5305;&#x542B;&#x56DB;&#x4E2A;&#x5730;&#x5740;&#x4FE1;&#x606F;: &#x4E24;&#x53F0;&#x8BA1;&#x7B97;&#x673A;&#x7684;IP&#x5730;&#x5740;&#x548C;&#x4E24;&#x4E2A;&#x8FDB;&#x7A0B;&#x6240;&#x4F7F;&#x7528;&#x7684;&#x7AEF;&#x53E3;(port)&#x3002;IP&#x5730;&#x5740;&#x7528;&#x4E8E;&#x5B9A;&#x4F4D;&#x8BA1;&#x7B97;&#x673A;&#xFF0C;&#x800C;port&#x7528;&#x4E8E;&#x5B9A;&#x4F4D;&#x8FDB;&#x7A0B; (&#x4E00;&#x53F0;&#x8BA1;&#x7B97;&#x673A;&#x4E0A;&#x53EF;&#x4EE5;&#x6709;&#x591A;&#x4E2A;&#x8FDB;&#x7A0B;&#x5206;&#x522B;&#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x7AEF;&#x53E3;)&#x3002;</p>
<p><img src="2012103111075988.jpg" alt="&#x4E00;&#x4E2A;TCP socket&#x8FDE;&#x63A5;&#x7684;&#x7F51;&#x7EDC;"></p>
<center>&#x4E00;&#x4E2A;TCP socket&#x8FDE;&#x63A5;&#x7684;&#x7F51;&#x7EDC;</center>



<h2 id="tcp-socket">TCP socket</h2>
<p>&#x5728;&#x4E92;&#x8054;&#x7F51;&#x4E0A;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8BA9;&#x67D0;&#x53F0;&#x8BA1;&#x7B97;&#x673A;&#x4F5C;&#x4E3A;&#x670D;&#x52A1;&#x5668;&#x3002;&#x670D;&#x52A1;&#x5668;&#x5F00;&#x653E;&#x81EA;&#x5DF1;&#x7684;&#x7AEF;&#x53E3;&#xFF0C;&#x88AB;&#x52A8;&#x7B49;&#x5F85;&#x5176;&#x4ED6;&#x8BA1;&#x7B97;&#x673A;&#x8FDE;&#x63A5;&#x3002;&#x5F53;&#x5176;&#x4ED6;&#x8BA1;&#x7B97;&#x673A;&#x4F5C;&#x4E3A;&#x5BA2;&#x6237;&#xFF0C;&#x4E3B;&#x52A8;&#x4F7F;&#x7528;socket&#x8FDE;&#x63A5;&#x5230;&#x670D;&#x52A1;&#x5668;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x670D;&#x52A1;&#x5668;&#x5C31;&#x5F00;&#x59CB;&#x4E3A;&#x5BA2;&#x6237;&#x63D0;&#x4F9B;&#x670D;&#x52A1;&#x3002;</p>
<p>&#x5728;Python&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x6807;&#x51C6;&#x5E93;&#x4E2D;&#x7684;socket&#x5305;&#x6765;&#x8FDB;&#x884C;&#x5E95;&#x5C42;&#x7684;socket&#x7F16;&#x7A0B;&#x3002;</p>
<p>&#x9996;&#x5148;&#x662F;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;bind()&#x65B9;&#x6CD5;&#x6765;&#x8D4B;&#x4E88;socket&#x4EE5;&#x56FA;&#x5B9A;&#x7684;&#x5730;&#x5740;&#x548C;&#x7AEF;&#x53E3;&#xFF0C;&#x5E76;&#x4F7F;&#x7528;listen()&#x65B9;&#x6CD5;&#x6765;&#x88AB;&#x52A8;&#x7684;&#x76D1;&#x542C;&#x8BE5;&#x7AEF;&#x53E3;&#x3002;&#x5F53;&#x6709;&#x5BA2;&#x6237;&#x5C1D;&#x8BD5;&#x7528;connect()&#x65B9;&#x6CD5;&#x8FDE;&#x63A5;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x670D;&#x52A1;&#x5668;&#x4F7F;&#x7528;accept()&#x63A5;&#x53D7;&#x8FDE;&#x63A5;&#xFF0C;&#x4ECE;&#x800C;&#x5EFA;&#x7ACB;&#x4E00;&#x4E2A;&#x8FDE;&#x63A5;&#x7684;socket&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment"># Server side</span>
<span class="hljs-keyword">import</span> socket

<span class="hljs-comment"># Address</span>
HOST = <span class="hljs-string">&apos;&apos;</span>
PORT = <span class="hljs-number">8000</span>

reply = <span class="hljs-string">&apos;Yes&apos;</span>

<span class="hljs-comment"># Configure socket</span>
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))

<span class="hljs-comment"># passively wait, 3: maximum number of connections in the queue</span>
s.listen(<span class="hljs-number">3</span>)
<span class="hljs-comment"># accept and establish connection</span>
conn, addr = s.accept()
<span class="hljs-comment"># receive message</span>
request    = conn.recv(<span class="hljs-number">1024</span>)

<span class="hljs-keyword">print</span> <span class="hljs-string">&apos;request is: &apos;</span>,request
<span class="hljs-keyword">print</span> <span class="hljs-string">&apos;Connected by&apos;</span>, addr
<span class="hljs-comment"># send message</span>
conn.sendall(reply)
<span class="hljs-comment"># close connection</span>
conn.close()
</code></pre>
<p>socket.socket()&#x521B;&#x5EFA;&#x4E00;&#x4E2A;socket&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x8BF4;&#x660E;socket&#x4F7F;&#x7528;&#x7684;&#x662F;IPv4(AF_INET&#xFF0C;IP version 4)&#x548C;TCP&#x534F;&#x8BAE;(SOCK_STREAM)&#x3002;</p>
<p>&#x7136;&#x540E;&#x7528;&#x53E6;&#x4E00;&#x53F0;&#x7535;&#x8111;&#x4F5C;&#x4E3A;&#x5BA2;&#x6237;&#xFF0C;&#x6211;&#x4EEC;&#x4E3B;&#x52A8;&#x4F7F;&#x7528;connect()&#x65B9;&#x6CD5;&#x6765;&#x641C;&#x7D22;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x7684;IP&#x5730;&#x5740;(&#x5728;Linux&#x4E2D;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x7528;$ifconfig&#x6765;&#x67E5;&#x8BE2;&#x81EA;&#x5DF1;&#x7684;IP&#x5730;&#x5740;)&#x548C;&#x7AEF;&#x53E3;&#xFF0C;&#x4EE5;&#x4FBF;&#x5BA2;&#x6237;&#x53EF;&#x4EE5;&#x627E;&#x5230;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5E76;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;:</p>
<pre><code class="lang-python"><span class="hljs-comment"># Client side</span>
<span class="hljs-keyword">import</span> socket

<span class="hljs-comment"># Address</span>
HOST = <span class="hljs-string">&apos;172.20.202.155&apos;</span>
PORT = <span class="hljs-number">8000</span>

request = <span class="hljs-string">&apos;can you hear me?&apos;</span>

<span class="hljs-comment"># configure socket</span>
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

<span class="hljs-comment"># send message</span>
s.sendall(request)
<span class="hljs-comment"># receive message</span>
reply = s.recv(<span class="hljs-number">1024</span>)
<span class="hljs-keyword">print</span> <span class="hljs-string">&apos;reply is: &apos;</span>,reply
<span class="hljs-comment"># close connection</span>
s.close()
</code></pre>
<p>&#x5728;&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5BF9;socket&#x7684;&#x4E24;&#x7AEF;&#x90FD;&#x53EF;&#x4EE5;&#x8C03;&#x7528;recv()&#x65B9;&#x6CD5;&#x6765;&#x63A5;&#x6536;&#x4FE1;&#x606F;&#xFF0C;&#x8C03;&#x7528;sendall()&#x65B9;&#x6CD5;&#x6765;&#x53D1;&#x9001;&#x4FE1;&#x606F;&#x3002;&#x8FD9;&#x6837;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x5728;&#x5206;&#x5904;&#x4E8E;&#x4E24;&#x53F0;&#x8BA1;&#x7B97;&#x673A;&#x7684;&#x4E24;&#x4E2A;&#x8FDB;&#x7A0B;&#x95F4;&#x8FDB;&#x884C;&#x901A;&#x4FE1;&#x4E86;&#x3002;&#x5F53;&#x901A;&#x4FE1;&#x7ED3;&#x675F;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;close()&#x65B9;&#x6CD5;&#x6765;&#x5173;&#x95ED;socket&#x8FDE;&#x63A5;&#x3002;</p>
<p>(&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4E24;&#x53F0;&#x8BA1;&#x7B97;&#x673A;&#x505A;&#x5B9E;&#x9A8C;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5C06;&#x5BA2;&#x6237;&#x7AEF;IP&#x60F3;&#x8981;connect&#x7684;IP&#x6539;&#x4E3A;&quot;127.0.0.1&quot;&#xFF0C;&#x8FD9;&#x662F;&#x4E2A;&#x7279;&#x6B8A;&#x7684;IP&#x5730;&#x5740;&#xFF0C;&#x7528;&#x6765;&#x8FDE;&#x63A5;&#x5F53;&#x5730;&#x4E3B;&#x673A;&#x3002;)</p>
<h2 id="&#x57FA;&#x4E8E;tcp-socket&#x7684;http&#x670D;&#x52A1;&#x5668;">&#x57FA;&#x4E8E;TCP socket&#x7684;HTTP&#x670D;&#x52A1;&#x5668;</h2>
<p>&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;TCP socket&#x6765;&#x4E3A;&#x4E24;&#x53F0;&#x8FDC;&#x7A0B;&#x8BA1;&#x7B97;&#x673A;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x3002;&#x7136;&#x800C;&#xFF0C;socket&#x4F20;&#x8F93;&#x81EA;&#x7531;&#x5EA6;&#x592A;&#x9AD8;&#xFF0C;&#x4ECE;&#x800C;&#x5E26;&#x6765;&#x5F88;&#x591A;&#x5B89;&#x5168;&#x548C;&#x517C;&#x5BB9;&#x7684;&#x95EE;&#x9898;&#x3002;&#x6211;&#x4EEC;&#x5F80;&#x5F80;&#x5229;&#x7528;&#x4E00;&#x4E9B;&#x5E94;&#x7528;&#x5C42;&#x7684;&#x534F;&#x8BAE;(&#x6BD4;&#x5982;HTTP&#x534F;&#x8BAE;)&#x6765;&#x89C4;&#x5B9A;socket&#x4F7F;&#x7528;&#x89C4;&#x5219;&#xFF0C;&#x4EE5;&#x53CA;&#x6240;&#x4F20;&#x8F93;&#x4FE1;&#x606F;&#x7684;&#x683C;&#x5F0F;&#x3002;</p>
<p>HTTP&#x534F;&#x8BAE;&#x5229;&#x7528;&#x8BF7;&#x6C42;-&#x56DE;&#x5E94;(request-response)&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x4F7F;&#x7528;TCP socket&#x3002;&#x5BA2;&#x6237;&#x7AEF;&#x5411;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x4E00;&#x6BB5;&#x6587;&#x672C;&#x4F5C;&#x4E3A;request&#xFF0C;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x5728;&#x63A5;&#x6536;&#x5230;request&#x4E4B;&#x540E;&#xFF0C;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x9001;&#x4E00;&#x6BB5;&#x6587;&#x672C;&#x4F5C;&#x4E3A;response&#x3002;&#x5728;&#x5B8C;&#x6210;&#x4E86;&#x8FD9;&#x6837;&#x4E00;&#x6B21;request-response&#x4EA4;&#x6613;&#x4E4B;&#x540E;&#xFF0C;TCP socket&#x88AB;&#x5E9F;&#x5F03;&#x3002;&#x4E0B;&#x6B21;&#x7684;request&#x5C06;&#x5EFA;&#x7ACB;&#x65B0;&#x7684;socket&#x3002;request&#x548C;response&#x672C;&#x8D28;&#x4E0A;&#x8BF4;&#x662F;&#x4E24;&#x4E2A;&#x6587;&#x672C;&#xFF0C;&#x53EA;&#x662F;HTTP&#x534F;&#x8BAE;&#x5BF9;&#x8FD9;&#x4E24;&#x4E2A;&#x6587;&#x672C;&#x90FD;&#x6709;&#x4E00;&#x5B9A;&#x7684;&#x683C;&#x5F0F;&#x8981;&#x6C42;&#x3002;</p>
<p>&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x5199;&#x51FA;&#x4E00;&#x4E2A;HTTP&#x670D;&#x52A1;&#x5668;&#x7AEF;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> socket

<span class="hljs-comment"># Address</span>
HOST = <span class="hljs-string">&apos;&apos;</span>
PORT = <span class="hljs-number">8000</span>

<span class="hljs-comment"># Prepare HTTP response</span>
text_content = <span class="hljs-string">&apos;&apos;&apos;HTTP/1.x 200 OK  
Content-Type: text/html

&lt;head&gt;
&lt;title&gt;WOW&lt;/title&gt;
&lt;/head&gt;
&lt;html&gt;
&lt;p&gt;Wow, Python Server&lt;/p&gt;
&lt;IMG src=&quot;test.jpg&quot;/&gt;
&lt;/html&gt;
&apos;&apos;&apos;</span>

<span class="hljs-comment"># Read picture, put into HTTP format</span>
f = open(<span class="hljs-string">&apos;test.jpg&apos;</span>,<span class="hljs-string">&apos;rb&apos;</span>)
pic_content = <span class="hljs-string">&apos;&apos;&apos;HTTP/1.x 200 OK  
Content-Type: image/jpg

&apos;&apos;&apos;</span>
pic_content = pic_content + f.read()
f.close()

<span class="hljs-comment"># Configure socket</span>
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))

<span class="hljs-comment"># infinite loop, server forever</span>
<span class="hljs-keyword">while</span> <span class="hljs-keyword">True</span>:
    <span class="hljs-comment"># 3: maximum number of requests waiting</span>
    s.listen(<span class="hljs-number">3</span>)
    conn, addr = s.accept()
    request    = conn.recv(<span class="hljs-number">1024</span>)
    method    = request.split(<span class="hljs-string">&apos; &apos;</span>)[<span class="hljs-number">0</span>]
    src            = request.split(<span class="hljs-string">&apos; &apos;</span>)[<span class="hljs-number">1</span>]

    <span class="hljs-comment"># deal with GET method</span>
    <span class="hljs-keyword">if</span> method == <span class="hljs-string">&apos;GET&apos;</span>:
        <span class="hljs-comment"># ULR    </span>
        <span class="hljs-keyword">if</span> src == <span class="hljs-string">&apos;/test.jpg&apos;</span>:
            content = pic_content
        <span class="hljs-keyword">else</span>: content = text_content

        <span class="hljs-keyword">print</span> <span class="hljs-string">&apos;Connected by&apos;</span>, addr
        <span class="hljs-keyword">print</span> <span class="hljs-string">&apos;Request is:&apos;</span>, request
        conn.sendall(content)
    <span class="hljs-comment"># close connection</span>
    conn.close()
</code></pre>
<h2 id="&#x6DF1;&#x5165;http&#x670D;&#x52A1;&#x5668;&#x7A0B;&#x5E8F;">&#x6DF1;&#x5165;HTTP&#x670D;&#x52A1;&#x5668;&#x7A0B;&#x5E8F;</h2>
<p>&#x5982;&#x6211;&#x4EEC;&#x4E0A;&#x9762;&#x6240;&#x770B;&#x5230;&#x7684;&#xFF0C;&#x670D;&#x52A1;&#x5668;&#x4F1A;&#x6839;&#x636E;request&#x5411;&#x5BA2;&#x6237;&#x4F20;&#x8F93;&#x7684;&#x4E24;&#x6761;&#x4FE1;&#x606F;text_content&#x548C;pic_content&#x4E2D;&#x7684;&#x4E00;&#x6761;&#xFF0C;&#x4F5C;&#x4E3A;response&#x6587;&#x672C;&#x3002;&#x6574;&#x4E2A;response&#x5206;&#x4E3A;&#x8D77;&#x59CB;&#x884C;(start line), &#x5934;&#x4FE1;&#x606F;(head)&#x548C;&#x4E3B;&#x4F53;(body)&#x4E09;&#x90E8;&#x5206;&#x3002;&#x8D77;&#x59CB;&#x884C;&#x5C31;&#x662F;&#x7B2C;&#x4E00;&#x884C;&#xFF1A;</p>
<pre><code class="lang-http">HTTP/1.x <span class="hljs-number">200</span> OK
</code></pre>
<p>&#x5B83;&#x5B9E;&#x9645;&#x4E0A;&#x53C8;&#x7531;&#x7A7A;&#x683C;&#x5206;&#x4E3A;&#x4E09;&#x4E2A;&#x7247;&#x6BB5;&#xFF0C;HTTP/1.x&#x8868;&#x793A;&#x6240;&#x4F7F;&#x7528;&#x7684;HTTP&#x7248;&#x672C;&#xFF0C;200&#x8868;&#x793A;&#x72B6;&#x6001;(status code)&#xFF0C;200&#x662F;HTTP&#x534F;&#x8BAE;&#x89C4;&#x5B9A;&#x7684;&#xFF0C;&#x8868;&#x793A;&#x670D;&#x52A1;&#x5668;&#x6B63;&#x5E38;&#x63A5;&#x6536;&#x5E76;&#x5904;&#x7406;&#x8BF7;&#x6C42;&#xFF0C;OK&#x662F;&#x4F9B;&#x4EBA;&#x6765;&#x9605;&#x8BFB;&#x7684;status code&#x3002;</p>
<p>&#x5934;&#x4FE1;&#x606F;&#x8DDF;&#x968F;&#x8D77;&#x59CB;&#x884C;&#xFF0C;&#x5B83;&#x548C;&#x4E3B;&#x4F53;&#x4E4B;&#x95F4;&#x6709;&#x4E00;&#x4E2A;&#x7A7A;&#x884C;&#x3002;&#x8FD9;&#x91CC;&#x7684;text_content&#x6216;&#x8005;pic_content&#x90FD;&#x53EA;&#x6709;&#x4E00;&#x884C;&#x7684;&#x5934;&#x4FE1;&#x606F;&#xFF0C;text_content&#x7528;&#x6765;&#x8868;&#x793A;&#x4E3B;&#x4F53;&#x4FE1;&#x606F;&#x7684;&#x7C7B;&#x578B;&#x4E3A;html&#x6587;&#x672C;&#xFF1A;</p>
<pre><code class="lang-HTTP"><span class="hljs-attribute">Content-Type</span>: text/html
</code></pre>
<p>&#x800C;pic_content&#x7684;&#x5934;&#x4FE1;&#x606F;(Content-Type: image/jpg)&#x8BF4;&#x660E;&#x4E3B;&#x4F53;&#x7684;&#x7C7B;&#x578B;&#x4E3A;jpg&#x56FE;&#x7247;(image/jpg)&#x3002;</p>
<p>&#x4E3B;&#x4F53;&#x4FE1;&#x606F;&#x4E3A;html&#x6216;&#x8005;jpg&#x6587;&#x4EF6;&#x7684;&#x5185;&#x5BB9;&#x3002;</p>
<p>(&#x6CE8;&#x610F;&#xFF0C;&#x5BF9;&#x4E8E;jpg&#x6587;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&apos;rb&apos;&#x6A21;&#x5F0F;&#x6253;&#x5F00;&#xFF0C;&#x662F;&#x4E3A;&#x4E86;&#x4E0E;windows&#x517C;&#x5BB9;&#x3002;&#x56E0;&#x4E3A;&#x5728;windows&#x4E0B;&#xFF0C;jpg&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x4E8C;&#x8FDB;&#x5236;(binary)&#x6587;&#x4EF6;&#xFF0C;&#x5728;UNIX&#x7CFB;&#x7EDF;&#x4E0B;&#xFF0C;&#x5219;&#x4E0D;&#x9700;&#x8981;&#x533A;&#x5206;&#x6587;&#x672C;&#x6587;&#x4EF6;&#x548C;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;&#x3002;)</p>
<p>&#x6211;&#x4EEC;&#x5E76;&#x6CA1;&#x6709;&#x5199;&#x5BA2;&#x6237;&#x7AEF;&#x7A0B;&#x5E8F;&#xFF0C;&#x540E;&#x9762;&#x6211;&#x4EEC;&#x4F1A;&#x7528;&#x6D4F;&#x89C8;&#x5668;&#x4F5C;&#x4E3A;&#x5BA2;&#x6237;&#x7AEF;&#x3002;request&#x7531;&#x5BA2;&#x6237;&#x7AEF;&#x7A0B;&#x5E8F;&#x53D1;&#x7ED9;&#x670D;&#x52A1;&#x5668;&#x3002;&#x5C3D;&#x7BA1;request&#x4E5F;&#x53EF;&#x4EE5;&#x50CF;response&#x90A3;&#x6837;&#x5206;&#x4E3A;&#x4E09;&#x90E8;&#x5206;&#xFF0C;request&#x7684;&#x683C;&#x5F0F;&#x4E0E;response&#x7684;&#x683C;&#x5F0F;&#x5E76;&#x4E0D;&#x76F8;&#x540C;&#x3002;request&#x7531;&#x5BA2;&#x6237;&#x53D1;&#x9001;&#x7ED9;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x6BD4;&#x5982;&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;request&#xFF1A;</p>
<pre><code class="lang-http">GET /test.jpg HTTP/1.x
Accept: text/*
</code></pre>
<p>&#x8D77;&#x59CB;&#x884C;&#x53EF;&#x4EE5;&#x5206;&#x4E3A;&#x4E09;&#x90E8;&#x5206;&#xFF0C;&#x7B2C;&#x4E00;&#x90E8;&#x5206;&#x4E3A;&#x8BF7;&#x6C42;&#x65B9;&#x6CD5;(request method)&#xFF0C;&#x7B2C;&#x4E8C;&#x90E8;&#x5206;&#x662F;URL&#xFF0C;&#x7B2C;&#x4E09;&#x90E8;&#x5206;&#x4E3A;HTTP&#x7248;&#x672C;&#x3002;request method&#x53EF;&#x4EE5;&#x6709;GET&#xFF0C; PUT&#xFF0C; POST&#xFF0C; DELETE&#xFF0C; HEAD&#x3002;&#x6700;&#x5E38;&#x7528;&#x7684;&#x4E3A;GET&#x548C;POST&#x3002;GET&#x662F;&#x8BF7;&#x6C42;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x9001;&#x8D44;&#x6E90;&#x7ED9;&#x5BA2;&#x6237;&#xFF0C;POST&#x662F;&#x8BF7;&#x6C42;&#x670D;&#x52A1;&#x5668;&#x63A5;&#x6536;&#x5BA2;&#x6237;&#x9001;&#x6765;&#x7684;&#x6570;&#x636E;&#x3002;&#x5F53;&#x6211;&#x4EEC;&#x6253;&#x5F00;&#x4E00;&#x4E2A;&#x7F51;&#x9875;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x901A;&#x5E38;&#x662F;&#x4F7F;&#x7528;GET&#x65B9;&#x6CD5;&#xFF1B;&#x5F53;&#x6211;&#x4EEC;&#x586B;&#x5199;&#x8868;&#x683C;&#x5E76;&#x63D0;&#x4EA4;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x901A;&#x5E38;&#x4F7F;&#x7528;POST&#x65B9;&#x6CD5;&#x3002;&#x7B2C;&#x4E8C;&#x90E8;&#x5206;&#x4E3A;URL&#xFF0C;&#x5B83;&#x901A;&#x5E38;&#x6307;&#x5411;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;(&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x7684;&#x8D44;&#x6E90;&#x6216;&#x8005;&#x5176;&#x5B83;&#x5730;&#x65B9;&#x7684;&#x8D44;&#x6E90;)&#x3002;&#x50CF;&#x73B0;&#x5728;&#x8FD9;&#x6837;&#xFF0C;&#x5C31;&#x662F;&#x6307;&#x5411;&#x5F53;&#x524D;&#x670D;&#x52A1;&#x5668;&#x7684;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x7684;test.jpg&#x3002;</p>
<p>&#x6309;&#x7167;HTTP&#x534F;&#x8BAE;&#x7684;&#x89C4;&#x5B9A;&#xFF0C;&#x670D;&#x52A1;&#x5668;&#x9700;&#x8981;&#x6839;&#x636E;&#x8BF7;&#x6C42;&#x6267;&#x884C;&#x4E00;&#x5B9A;&#x7684;&#x64CD;&#x4F5C;&#x3002;&#x6B63;&#x5982;&#x6211;&#x4EEC;&#x5728;&#x670D;&#x52A1;&#x5668;&#x7A0B;&#x5E8F;&#x4E2D;&#x770B;&#x5230;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x7684;Python&#x7A0B;&#x5E8F;&#x5148;&#x68C0;&#x67E5;&#x4E86;request&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x968F;&#x540E;&#x6839;&#x636E;URL&#x7684;&#x4E0D;&#x540C;&#xFF0C;&#x6765;&#x751F;&#x6210;&#x4E0D;&#x540C;&#x7684;response(text_content&#x6216;&#x8005;pic_content)&#x3002;&#x968F;&#x540E;&#xFF0C;&#x8FD9;&#x4E2A;response&#x88AB;&#x53D1;&#x9001;&#x56DE;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</p>
<h2 id="&#x4F7F;&#x7528;&#x6D4F;&#x89C8;&#x5668;&#x5B9E;&#x9A8C;">&#x4F7F;&#x7528;&#x6D4F;&#x89C8;&#x5668;&#x5B9E;&#x9A8C;</h2>
<p>&#x4E3A;&#x4E86;&#x914D;&#x5408;&#x4E0A;&#x9762;&#x7684;&#x670D;&#x52A1;&#x5668;&#x7A0B;&#x5E8F;&#xFF0C;&#x6211;&#x5DF2;&#x7ECF;&#x5728;&#x653E;&#x7F6E;Python&#x7A0B;&#x5E8F;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x91CC;&#xFF0C;&#x4FDD;&#x5B58;&#x4E86;&#x4E00;&#x4E2A;test.jpg&#x56FE;&#x7247;&#x6587;&#x4EF6;&#x3002;&#x6211;&#x4EEC;&#x5728;&#x7EC8;&#x7AEF;&#x8FD0;&#x884C;&#x4E0A;&#x9762;&#x7684;Python&#x7A0B;&#x5E8F;&#xFF0C;&#x4F5C;&#x4E3A;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#xFF0C;&#x518D;&#x6253;&#x5F00;&#x4E00;&#x4E2A;&#x6D4F;&#x89C8;&#x5668;&#x4F5C;&#x4E3A;&#x5BA2;&#x6237;&#x7AEF;&#x3002;(&#x5982;&#x679C;&#x6709;&#x65F6;&#x95F4;&#xFF0C;&#x4F60;&#x4E5F;&#x5B8C;&#x5168;&#x53EF;&#x4EE5;&#x7528;Python&#x5199;&#x4E00;&#x4E2A;&#x5BA2;&#x6237;&#x7AEF;&#x3002;&#x539F;&#x7406;&#x4E0E;&#x4E0A;&#x9762;&#x7684;TCP socket&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x7A0B;&#x5E8F;&#x76F8;&#x7C7B;&#x4F3C;&#x3002;)</p>
<p>&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x5730;&#x5740;&#x680F;&#x8F93;&#x5165;:</p>
<p>127.0.0.1:8000</p>
<p>(&#x5F53;&#x7136;&#xFF0C;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x4EE4;&#x4E00;&#x53F0;&#x7535;&#x8111;&#xFF0C;&#x5E76;&#x8F93;&#x5165;&#x670D;&#x52A1;&#x5668;&#x7684;IP&#x5730;&#x5740;&#x3002;) &#x6211;&#x5F97;&#x5230;&#x4E0B;&#x9762;&#x7684;&#x7ED3;&#x679C;:</p>
<p><img src="2012103013565240.png" alt=""></p>
<p>OK&#xFF0C;&#x6211;&#x5DF2;&#x7ECF;&#x6709;&#x4E86;&#x4E00;&#x4E2A;&#x7528;Python&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x5E76;&#x4ECE;socket&#x5199;&#x8D77;&#x7684;&#x670D;&#x52A1;&#x5668;&#x4E86;&#x3002;</p>
<p>&#x4ECE;&#x7EC8;&#x7AEF;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x5B9E;&#x9645;&#x4E0A;&#x53D1;&#x51FA;&#x4E86;&#x4E24;&#x4E2A;&#x8BF7;&#x6C42;&#x3002;&#x7B2C;&#x4E00;&#x4E2A;&#x8BF7;&#x6C42;&#x4E3A; (&#x5173;&#x952E;&#x4FE1;&#x606F;&#x5728;&#x8D77;&#x59CB;&#x884C;&#xFF0C;&#x8FD9;&#x4E00;&#x4E2A;&#x8BF7;&#x6C42;&#x7684;&#x4E3B;&#x4F53;&#x4E3A;&#x7A7A;):</p>
<pre><code class="lang-HTTP"><span class="hljs-keyword">GET</span> <span class="hljs-string">/</span> HTTP/1.1
<span class="hljs-attribute">Host</span>: 127.0.0.1:8000
<span class="hljs-attribute">User-Agent</span>: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1
<span class="hljs-attribute">Accept</span>: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
<span class="hljs-attribute">Accept-Language</span>: en-us,en;q=0.5
<span class="hljs-attribute">Accept-Encoding</span>: gzip, deflate
<span class="hljs-attribute">Connection</span>: keep-alive
</code></pre>
<p>&#x6211;&#x4EEC;&#x7684;Python&#x7A0B;&#x5E8F;&#x6839;&#x636E;&#x8FD9;&#x4E2A;&#x8BF7;&#x6C42;&#xFF0C;&#x53D1;&#x9001;&#x7ED9;&#x670D;&#x52A1;&#x5668;text_content&#x7684;&#x5185;&#x5BB9;&#x3002;</p>
<p>&#x6D4F;&#x89C8;&#x5668;&#x63A5;&#x6536;&#x5230;text_content&#x4E4B;&#x540E;&#xFF0C;&#x53D1;&#x73B0;&#x6B63;&#x6587;&#x7684;html&#x6587;&#x672C;&#x4E2D;&#x6709;<code>&lt;IMG src=&quot;text.jpg&quot; /&gt;</code>&#xFF0C;&#x77E5;&#x9053;&#x9700;&#x8981;&#x83B7;&#x5F97;text.jpg&#x6587;&#x4EF6;&#x6765;&#x8865;&#x5145;&#x4E3A;&#x56FE;&#x7247;&#xFF0C;&#x7ACB;&#x5373;&#x53D1;&#x51FA;&#x4E86;&#x7B2C;&#x4E8C;&#x4E2A;&#x8BF7;&#x6C42;:</p>
<pre><code class="lang-HTTP"><span class="hljs-keyword">GET</span> <span class="hljs-string">/test.jpg</span> HTTP/1.1
<span class="hljs-attribute">Host</span>: 127.0.0.1:8000
<span class="hljs-attribute">User-Agent</span>: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1
<span class="hljs-attribute">Accept</span>: image/png,image/*;q=0.8,*/*;q=0.5
<span class="hljs-attribute">Accept-Language</span>: en-us,en;q=0.5
<span class="hljs-attribute">Accept-Encoding</span>: gzip, deflate
<span class="hljs-attribute">Connection</span>: keep-alive
<span class="hljs-attribute">Referer</span>: http://127.0.0.1:8000/
</code></pre>
<p>&#x6211;&#x4EEC;&#x7684;Python&#x7A0B;&#x5E8F;&#x5206;&#x6790;&#x8FC7;&#x8D77;&#x59CB;&#x884C;&#x4E4B;&#x540E;&#xFF0C;&#x53D1;&#x73B0;/test.jpg&#x7B26;&#x5408;if&#x6761;&#x4EF6;&#xFF0C;&#x6240;&#x4EE5;&#x5C06;pic_content&#x53D1;&#x9001;&#x7ED9;&#x5BA2;&#x6237;&#x3002;</p>
<p>&#x6700;&#x540E;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x6839;&#x636E;html&#x8BED;&#x8A00;&#x7684;&#x8BED;&#x6CD5;&#xFF0C;&#x5C06;html&#x6587;&#x672C;&#x548C;&#x56FE;&#x753B;&#x4EE5;&#x9002;&#x5F53;&#x7684;&#x65B9;&#x5F0F;&#x663E;&#x793A;&#x51FA;&#x6765;&#x3002;(html&#x53EF;&#x53C2;&#x8003;<a href="http://www.w3schools.com/html/default.asp" target="_blank">http://www.w3schools.com/html/default.asp</a>)</p>
<h2 id="&#x63A2;&#x7D22;&#x7684;&#x65B9;&#x5411;">&#x63A2;&#x7D22;&#x7684;&#x65B9;&#x5411;</h2>
<p>1) &#x5728;&#x6211;&#x4EEC;&#x4E0A;&#x9762;&#x7684;&#x670D;&#x52A1;&#x5668;&#x7A0B;&#x5E8F;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x7528;while&#x5FAA;&#x73AF;&#x6765;&#x8BA9;&#x670D;&#x52A1;&#x5668;&#x4E00;&#x76F4;&#x5DE5;&#x4F5C;&#x4E0B;&#x53BB;&#x3002;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x6211;&#x4E4B;&#x524D;&#x4ECB;&#x7ECD;&#x7684;&#x591A;&#x7EBF;&#x7A0B;&#x7684;&#x77E5;&#x8BC6;&#xFF0C;&#x5C06;while&#x5FAA;&#x73AF;&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#x6539;&#x4E3A;&#x591A;&#x8FDB;&#x7A0B;&#x6216;&#x8005;&#x591A;&#x7EBF;&#x7A0B;&#x5DE5;&#x4F5C;&#x3002;(&#x53C2;&#x8003;Python&#x591A;&#x7EBF;&#x7A0B;&#x4E0E;&#x540C;&#x6B65;&#xFF0C;Python&#x591A;&#x8FDB;&#x7A0B;&#x521D;&#x6B65;&#xFF0C;Python&#x591A;&#x8FDB;&#x7A0B;&#x63A2;&#x7D22;)</p>
<p>2) &#x6211;&#x4EEC;&#x7684;&#x670D;&#x52A1;&#x5668;&#x7A0B;&#x5E8F;&#x8FD8;&#x4E0D;&#x5B8C;&#x5584;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x7684;Python&#x7A0B;&#x5E8F;&#x8C03;&#x7528;Python&#x7684;&#x5176;&#x4ED6;&#x529F;&#x80FD;&#xFF0C;&#x4EE5;&#x5B9E;&#x73B0;&#x66F4;&#x590D;&#x6742;&#x7684;&#x529F;&#x80FD;&#x3002;&#x6BD4;&#x5982;&#x8BF4;&#x5236;&#x4F5C;&#x4E00;&#x4E2A;&#x65F6;&#x95F4;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x8BA9;&#x670D;&#x52A1;&#x5668;&#x5411;&#x5BA2;&#x6237;&#x8FD4;&#x56DE;&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;&#x3002;&#x4F60;&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;Python&#x81EA;&#x5E26;&#x7684;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x6765;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684;LAMP&#x670D;&#x52A1;&#x5668;&#x3002;</p>
<p>3) socket&#x5305;&#x662F;&#x6BD4;&#x8F83;&#x5E95;&#x5C42;&#x7684;&#x5305;&#x3002;Python&#x6807;&#x51C6;&#x5E93;&#x4E2D;&#x8FD8;&#x6709;&#x9AD8;&#x5C42;&#x7684;&#x5305;&#xFF0C;&#x6BD4;&#x5982;SocketServer&#xFF0C;SimpleHTTPServer&#xFF0C;CGIHTTPServer&#xFF0C;cgi&#x3002;&#x8FD9;&#x4E9B;&#x90FD;&#x5305;&#x90FD;&#x662F;&#x5728;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x66F4;&#x5BB9;&#x6613;&#x7684;&#x4F7F;&#x7528;socket&#x3002;&#x5982;&#x679C;&#x4F60;&#x5DF2;&#x7ECF;&#x4E86;&#x89E3;&#x4E86;socket&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E9B;&#x5305;&#x5C31;&#x5F88;&#x5BB9;&#x6613;&#x660E;&#x767D;&#x4E86;&#x3002;&#x5229;&#x7528;&#x8FD9;&#x4E9B;&#x9AD8;&#x5C42;&#x7684;&#x5305;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x5199;&#x4E00;&#x4E2A;&#x76F8;&#x5F53;&#x6210;&#x719F;&#x7684;&#x670D;&#x52A1;&#x5668;&#x3002;</p>
<p>4) &#x5728;&#x7ECF;&#x5386;&#x4E86;&#x6240;&#x6709;&#x7684;&#x8F9B;&#x82E6;&#x548C;&#x9EBB;&#x70E6;&#x4E4B;&#x540E;&#xFF0C;&#x4F60;&#x53EF;&#x80FD;&#x53D1;&#x73B0;&#xFF0C;&#x6846;&#x67B6;&#x662F;&#x90A3;&#x4E48;&#x7684;&#x65B9;&#x4FBF;&#xFF0C;&#x6240;&#x4EE5;&#x51B3;&#x5B9A;&#x53BB;&#x4F7F;&#x7528;&#x6846;&#x67B6;&#x3002;&#x6216;&#x8005;&#xFF0C;&#x4F60;&#x5DF2;&#x7ECF;&#x6709;&#x4E86;&#x53C2;&#x4E0E;&#x5230;&#x6846;&#x67B6;&#x5F00;&#x53D1;&#x7684;&#x70ED;&#x60C5;&#x3002;</p>
<p>&#x66F4;&#x591A;&#x5185;&#x5BB9;</p>
<p>TCP/IP&#x548C;port&#x53C2;&#x8003;: TCP/IP illustrated <a href="http://book.douban.com/subject/1741925/" target="_blank">http://book.douban.com/subject/1741925/</a></p>
<p>socket&#x53C2;&#x8003;: </p>
<ul>
<li>UNIX Network Programming <a href="http://book.douban.com/subject/1756533/" target="_blank">http://book.douban.com/subject/1756533/</a></li>
<li>Python socket &#x5B98;&#x65B9;&#x6587;&#x6863; <a href="http://docs.python.org/2/library/socket.html" target="_blank">http://docs.python.org/2/library/socket.html</a></li>
</ul>
<p>HTTP&#x53C2;&#x8003;: HTTP, the definitive guide <a href="http://book.douban.com/subject/1440226/" target="_blank">http://book.douban.com/subject/1440226/</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="应用.html" class="navigation navigation-prev " aria-label="Previous page: Python应用">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="网络01 原始服务器.html#tcpip和socket" class="navigation navigation-next " aria-label="Next page: TCP/IP和socket">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"应用01 原始服务器","level":"6.1.1","depth":2,"next":{"title":"TCP/IP和socket","level":"6.1.1.1","depth":3,"anchor":"#tcpip和socket","path":"网络01 原始服务器.md","ref":"网络01 原始服务器.md#tcpip和socket","articles":[]},"previous":{"title":"Python应用","level":"6.1","depth":1,"path":"应用.md","ref":"应用.md","articles":[{"title":"应用01 原始服务器","level":"6.1.1","depth":2,"path":"网络01 原始服务器.md","ref":"网络01 原始服务器.md","articles":[{"title":"TCP/IP和socket","level":"6.1.1.1","depth":3,"anchor":"#tcpip和socket","path":"网络01 原始服务器.md","ref":"网络01 原始服务器.md#tcpip和socket","articles":[]},{"title":"TCP socket","level":"6.1.1.2","depth":3,"anchor":"#tcp-socket","path":"网络01 原始服务器.md","ref":"网络01 原始服务器.md#tcp-socket","articles":[]},{"title":"基于TCP socket的HTTP服务器","level":"6.1.1.3","depth":3,"anchor":"#基于tcp-socket的http服务器","path":"网络01 原始服务器.md","ref":"网络01 原始服务器.md#基于tcp-socket的http服务器","articles":[]},{"title":"深入HTTP服务器程序","level":"6.1.1.4","depth":3,"anchor":"#深入http服务器程序","path":"网络01 原始服务器.md","ref":"网络01 原始服务器.md#深入http服务器程序","articles":[]},{"title":"使用浏览器实验","level":"6.1.1.5","depth":3,"anchor":"#使用浏览器实验","path":"网络01 原始服务器.md","ref":"网络01 原始服务器.md#使用浏览器实验","articles":[]},{"title":"探索的方向","level":"6.1.1.6","depth":3,"anchor":"#探索的方向","path":"网络01 原始服务器.md","ref":"网络01 原始服务器.md#探索的方向","articles":[]}]},{"title":"应用02 服务器进化","level":"6.1.2","depth":2,"path":"网络02 服务器进化.md","ref":"网络02 服务器进化.md","articles":[{"title":"支持POST","level":"6.1.2.1","depth":3,"anchor":"#支持post","path":"网络02 服务器进化.md","ref":"网络02 服务器进化.md#支持post","articles":[]},{"title":"使用SocketServer","level":"6.1.2.2","depth":3,"anchor":"#使用socketserver","path":"网络02 服务器进化.md","ref":"网络02 服务器进化.md#使用socketserver","articles":[]},{"title":"SimpleHTTPServer: 使用静态文件来回应请求","level":"6.1.2.3","depth":3,"anchor":"#simplehttpserver:-使用静态文件来回应请求","path":"网络02 服务器进化.md","ref":"网络02 服务器进化.md#simplehttpserver:-使用静态文件来回应请求","articles":[]},{"title":"CGIHTTPServer：使用静态文件或者CGI来回应请求","level":"6.1.2.4","depth":3,"anchor":"#cgihttpserver：使用静态文件或者cgi来回应请求","path":"网络02 服务器进化.md","ref":"网络02 服务器进化.md#cgihttpserver：使用静态文件或者cgi来回应请求","articles":[]},{"title":"总结","level":"6.1.2.5","depth":3,"anchor":"#总结","path":"网络02 服务器进化.md","ref":"网络02 服务器进化.md#总结","articles":[]}]},{"title":"应用03 使用PyQT制作视频播放器","level":"6.1.3","depth":2,"path":"网络03 使用pyqt制作视频播放器.md","ref":"网络03 使用pyqt制作视频播放器.md","articles":[{"title":"视频播放器","level":"6.1.3.1","depth":3,"anchor":"#视频播放器","path":"网络03 使用pyqt制作视频播放器.md","ref":"网络03 使用pyqt制作视频播放器.md#视频播放器","articles":[]},{"title":"视图部分","level":"6.1.3.2","depth":3,"anchor":"#视图部分","path":"网络03 使用pyqt制作视频播放器.md","ref":"网络03 使用pyqt制作视频播放器.md#视图部分","articles":[]},{"title":"多线程","level":"6.1.3.3","depth":3,"anchor":"#多线程","path":"网络03 使用pyqt制作视频播放器.md","ref":"网络03 使用pyqt制作视频播放器.md#多线程","articles":[]},{"title":"信号与槽","level":"6.1.3.4","depth":3,"anchor":"#信号与槽","path":"网络03 使用pyqt制作视频播放器.md","ref":"网络03 使用pyqt制作视频播放器.md#信号与槽","articles":[]}]}]},"dir":"ltr"},"config":{"plugins":["toggle-chapters","theme-comscore","livereload"],"root":"./content","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"toggle-chapters":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Python-Tutorial","language":"zh-hans","gitbook":"*","description":"A Quick Tutorial of Python"},"file":{"path":"网络01 原始服务器.md","mtime":"2021-03-21T16:06:56.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-03-22T11:11:10.529Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

